<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:cgf="http://www.centralgold.com.br/facelets"
    template="/layout/template.xhtml">

<ui:define name="body">

    <h:form id="tabelaForm">

        <rich:panel>
            <f:facet name="header">Cadastrar Tabelas</f:facet>
			
			<rich:dataTable id="tabelaTabelas" 
				value="#{cadastrarTabela.listaTabelas}"
				rows="10"
				onRowMouseOver="this.style.backgroundColor='#6495ED'"
       			onRowMouseOut="this.style.backgroundColor='#FFFFCC'"
				var="_tab">
				
				<rich:column width="10%">
					<f:facet name="header">
						<h:selectBooleanCheckbox value="#{cadastrarTabela.selecionadoTodos}" >
							<a:support event="onchange" 
								action="#{cadastrarTabela.selecionaTodos()}"
								reRender="tabelaTabelas"/>
						</h:selectBooleanCheckbox>
					</f:facet>
					<h:selectBooleanCheckbox value="#{_tab.selecionado}" />				
				</rich:column>
				
				<rich:column width="90%" filterBy="#{_tab.dscTabela}" filterEvent="onkeyup">
					<f:facet name="header">Descrição</f:facet>
					<h:outputText value="#{_tab.dscTabela}" />	
					<a:queue ignoreDupResponses="true"/>			
				</rich:column>
				
				<rich:column rendered="#{identity.hasRole('CADASTRAR_TABELAS_GRAVAR')}">
					<f:facet name="header"></f:facet>
					<h:commandButton value="EDITAR"
						image="/img/btn_editar.png"
						alt="EDITAR"
						title="EDITAR" 
						action="#{cadastrarTabela.editar(_tab)}" />				
				</rich:column>
				
			</rich:dataTable>
			<rich:datascroller for="tabelaTabelas" renderIfSinglePage="false"/>
        </rich:panel>

        <div class="actionButtons">
            <h:commandButton id="novo" value="Novo" action="#{cadastrarTabela.inicializaPopup()}"
            	rendered="#{identity.hasRole('CADASTRAR_TABELAS_GRAVAR')}"/>
            <h:commandButton id="excluir" value="Excluir" action="#{cadastrarTabela.excluir()}"
            	rendered="#{identity.hasRole('CADASTRAR_TABELAS_EXCLUIR')}"
            	onclick="javascript:if(!confirm('Tem certeza que deseja excluir?'))return false;"/>
        </div>

    </h:form>

	<rich:modalPanel id="modalTabela" height="150" width="400"
		 showWhenRendered="#{cadastrarTabela.exibePopupNovaTabela}">
         	<f:facet name="header">
            <h:panelGroup>
                <h:outputText value="Nova Tabela de Valor"/>
            </h:panelGroup>
        </f:facet>
	       
	    <h:form id="formModalTabela">
	    	<h:panelGrid columns="1">
	    		<s:decorate template="/layout/edit.xhtml">
	    			<ui:define name="label">Descrição</ui:define>
	    			<h:inputText value="#{cadastrarTabela.tabelaEdicao.dscTabela}"
	    				required="true" 
	    				maxlength="100"
	    				size="40"/>
	    		</s:decorate>
	    	</h:panelGrid>
	    	<div align="center">
	    		<h:commandButton action="#{cadastrarTabela.salvar()}" value="Salvar" 
	    			onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;"/>
	    		<h:commandButton action="#{cadastrarTabela.cancelar()}" value="Cancelar" 
	    			immediate="true"/>
	    	</div>
	    </h:form>
	</rich:modalPanel>
 </ui:define>
</ui:composition>
